test: deterministic debounce test via synctest#745
Open
JamBalaya56562 wants to merge 1 commit into
Open
Conversation
5ea2754 to
b916e5c
Compare
There was a problem hiding this comment.
Pull request overview
This PR removes the flaky, wall-clock/network-driven debounce integration test (TestGenerateFromEvents) and replaces it with deterministic unit tests for newDebounceChannel using Go’s testing/synctest, addressing nondeterministic timing failures reported in #238.
Changes:
- Replaced
TestGenerateFromEvents(dockertest server + realtime.Sleep) withTestNewDebounceChannelbuilt ontesting/synctest. - Added deterministic subtests covering:
Min == 0passthrough,Minquiet-period coalescing, andMaxcap behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9632402 to
6cbdd3a
Compare
Member
|
@JamBalaya56562 same thing here, no issue or PR numbers in either PR titles or commit message. |
6cbdd3a to
6b64045
Compare
Contributor
Author
|
Done — dropped the issue number from the title and commit message, thanks! |
6b64045 to
56ac89c
Compare
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
56ac89c to
5e508d0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TestGenerateFromEventsdrives the debounce logic through a realdockertestHTTP server and wall-clocktime.Sleepcalls, so the timing of debounce firings races the OS scheduler / timer resolution and the test fails nondeterministically (off-by-one or worse). It reproduces onmainand is especially flaky on Windows. See #238.This PR replaces it with
TestNewDebounceChannel, which exercisesnewDebounceChanneldirectly inside atesting/synctestbubble. The fake clock makes theMinquiet-period coalescing and theMaxcap fire at exact, reproducible virtual times, removing the real network and wall-clock dependence entirely.Changes
internal/generator/generator_test.go: replaceTestGenerateFromEventswithTestNewDebounceChannel. Three deterministic subtests:Min == 0,Minquiet-period coalescing (a burst collapses to one event, firedMinafter the last event),Maxcap (output is forced out atMaxwhile events keep arriving).Notes
newDebounceChannelalready usestime.After, whichsynctestvirtualizes.testing/synctestis stable as of Go 1.25 (go.moddeclaresgo 1.25.5; the CI matrix tests Go 1.25 and 1.26). It is OS-independent, which removes the Windows timer-resolution flakiness at its root.go test -run TestNewDebounceChannel -count=200passes.Fixes #238